package com.binhai.springboot.project.controller;

import com.binhai.springboot.project.bean.ProjectBean;
import com.binhai.springboot.project.service.ProjectService;
import com.binhai.springboot.user.bean.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    private ProjectService service;


    @RequestMapping("/toMain.do")
    public String toMain(){

        return "project/main";
    }

    @RequestMapping("/getAllData.do")
    @ResponseBody
    public List getAllData(){

        return service.getAllData();
    }


    @RequestMapping("/selectData.do")
    @ResponseBody
    public List selectData(@RequestBody ProjectBean bean){

        return service.selectData(bean.getName ());
    }

    @RequestMapping("/saveData.do")
    @ResponseBody
    public Map saveUser(@RequestBody ProjectBean bean){

        return service.saveData(bean);
    }
    @RequestMapping("/updateData.do")
    @ResponseBody
    public Map updateUser(@RequestBody ProjectBean bean){

        return service.updateData(bean);
    }
    @RequestMapping("/deleteData.do")
    @ResponseBody
    public Map deleteUser(@RequestBody ProjectBean bean){

        return service.deleteData(bean);
    }

    @RequestMapping("/deleteDatas.do")
    @ResponseBody
    public Map deleteDatas(/* @ResponseBody*/int[] ids){
//在上传文件的时候，spring框架会自动装配文件类型, 使用@RequestBody接收对象，所对应的content-type :application/json。所以当使用@RequestBody和文件上传的时候，会报错。
//
//解决办法：去掉@RequestBody注解
        return service.deleteDatas(ids);
    }
}
